// 文章模块的数据
const initialState = {
  channels: [],
  list: [], // 文章列表
  total: 0, // 文章总数
};

export const article = (state = initialState, action) => {
  // 处理频道数据
  if (action.type === 'article/getChannels') {
    return {
      ...state,
      channels: action.payload,
    };
  }

  // 处理文章列表数据
  if (action.type === 'article/getArticles') {
    return {
      ...state,
      ...action.payload, // 把action展开覆盖原来的对象
    };
    // 这种写法和上面等价的
    // return {
    //   ...state,
    //   list: action.payload.list,
    //   total: action.payload.total,
    // };
  }

  return state;
};
